﻿using UnityEngine;

[RequireComponent(typeof(Player))]
[RequireComponent(typeof(Animator))]
public class MovementAbility : PhysicsObject {

    public float maxSpeed = 7;
    public float jumpTakeOffSpeed = 7;

    private Animator animator;

	public void Start () {
        animator = GetComponent<Animator>();
    }

    protected override void ComputeVelocity()
    {
        if(player.CurrentSate == PlayerState.Slid)
        {
            targetVelocity = Vector2.zero;
        }
        else
        {
            player.Grounded = grounded;
            if (Input.GetButtonDown("Jump") && grounded && velocity.y == 0)
            {
                velocity.y = jumpTakeOffSpeed;
            }
            //else if (Input.GetButtonUp("Jump"))
            //{
            //    if (velocity.y > 0)
            //    {
            //        velocity.y = velocity.y * 0.5f;
            //    }
            //}

            animator.SetBool("grounded", grounded);
            animator.SetFloat("velocityX", Mathf.Abs(velocity.x) / maxSpeed);
            targetVelocity = player.Move * maxSpeed;
        }
    }

    public void ToMovement(Vector2 move,bool yMovement)
    {
        Movement(move, yMovement);
    }
}
